package com.neusoft.neuiotms.dcom.converter.hn;

import java.util.Map;

import org.springframework.stereotype.Component;

import com.neusoft.bizcore.web.dto.AbstractConverter;
import com.neusoft.neuiotms.dcom.dto.hn.HnInspectionTaskAssetDTO;
import com.neusoft.neuiotms.dcom.model.hn.HnInspectionTaskAsset;

@Component
public class HnInspectionTaskAssetConverter extends AbstractConverter<HnInspectionTaskAsset, HnInspectionTaskAssetDTO> {

    @Override
    public HnInspectionTaskAsset toModel(final HnInspectionTaskAssetDTO dto) {
        final HnInspectionTaskAsset model = new HnInspectionTaskAsset();
        model.setAssetId(dto.getAssetId());
        model.setBrand(dto.getBrand());
        model.setCode(dto.getCode());
        model.setLocated(dto.getLocated());
        model.setName(dto.getName());
        model.setOnline(dto.isOnline());
        model.setSpecification(dto.getSpecification());
        model.setTypeCode(dto.getTypeCode());
        model.setTypeName(dto.getTypeName());
        return model;
    }

    @Override
    public HnInspectionTaskAssetDTO toDTO(final HnInspectionTaskAsset model, final boolean forListView) {
        final HnInspectionTaskAssetDTO dto = new HnInspectionTaskAssetDTO();
        dto.setAssetId(model.getAssetId());
        dto.setBrand(model.getBrand());
        dto.setCode(model.getCode());
        dto.setId(model.getId());
        dto.setLocated(model.getLocated());
        dto.setName(model.getName());
        dto.setOnline(model.isOnline());
        dto.setSpecification(model.getSpecification());
        dto.setTypeCode(model.getTypeCode());
        dto.setTypeName(model.getTypeName());
        return dto;
    }

    public HnInspectionTaskAsset toModel(final Map<String, Object> map) {
        final HnInspectionTaskAsset model = new HnInspectionTaskAsset();
        if (map.containsKey("id")) {
            model.setAssetId(Long.valueOf(map.get("id").toString()));
        }
        if (map.containsKey("brand") && (null != map.get("brand"))) {
            model.setBrand(map.get("brand").toString());
        }
        if (map.containsKey("code") && (null != map.get("code"))) {
            model.setCode(map.get("code").toString());
        }
        if (map.containsKey("located") && (null != map.get("located"))) {
            model.setLocated(map.get("located").toString());
        }
        if (map.containsKey("name") && (null != map.get("name"))) {
            model.setName(map.get("name").toString());
        }
        if (map.containsKey("specification") && (null != map.get("specification"))) {
            model.setSpecification(map.get("specification").toString());
        }
        if (map.containsKey("assetTypeCode") && (null != map.get("assetTypeCode"))) {
            model.setTypeCode(map.get("assetTypeCode").toString());
        }
        if (map.containsKey("assetTypeName") && (null != map.get("assetTypeName"))) {
            model.setTypeName(map.get("assetTypeName").toString());
        }

        //        //设置默认在线
        //        model.setOnline(true);
        return model;
    }

}
